﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections;
using SmartSpace.UI.Silverlight.Dynamic.DynamicRef;
using System.Collections.ObjectModel;
using System.Text;

namespace SmartSpace.UI.Silverlight.Dynamic.Controls
{
    /// <summary>
    /// 公用日期时间选择控件
    /// </summary>
    public partial class DateTimeControl : PMFDataControl
    {
        public DateTimeControl()
        {
            InitializeComponent();
        }

        #region Overrides

        public override void UpdateSource()
        {
            if (m_datePicker.SelectedDate != null)
            {
                DataSource.Value = m_datePicker.SelectedDate.Value.ToString("yyyy-MM-dd");
                DataSource.Text = DataSource.Value;
            }
            this.GetBindingExpression(PMFDataControl.DataSourceProperty).UpdateSource();
        }


        protected override void OnIsReadOnlyChanged(bool isReadOnly)
        {
            if (isReadOnly)
            {
                m_txtDate.Visibility = System.Windows.Visibility.Visible;
                this.m_datePicker.Visibility = System.Windows.Visibility.Collapsed;
            }
            else
            {
                m_txtDate.Visibility = System.Windows.Visibility.Collapsed;
                m_datePicker.Visibility = System.Windows.Visibility.Visible;
            }
        }

        protected override void OnDataSourceChanged(FieldInstance dataSource)
        {
            if (!string.IsNullOrEmpty(dataSource.Text))
            {
                m_datePicker.SelectedDate = Convert.ToDateTime(dataSource.Text);
            }
        }

        #endregion
    }

    public class MyDatePicker : DatePicker
    {
        protected override void OnMouseWheel(MouseWheelEventArgs e)
        {
            //base.OnMouseWheel(e);
        }
    }
}
